package com.taobao.yugong.translator;

import com.taobao.yugong.common.db.meta.ColumnMeta;
import com.taobao.yugong.common.db.meta.ColumnValue;
import com.taobao.yugong.common.model.record.Record;

import java.sql.Types;

/**
 * 一个迁移的例子，涵盖一些基本转换操作
 *
 * <pre>
 * 例子包含特性：
 * 1. schema/table名不同. oracle中为yugong_example_oracle，mysql中为test.yugong_example_mysql
 * 2. 字段名字不同.  oracle中的name字段，映射到mysql的display_name
 * 3. 字段逻辑处理.  mysql的display_name字段数据来源为oracle库的:name+'('alias_name+')'
 * 4. 字段类型不同.  oracle中的amount为number类型，映射到mysql的amount为varchar文本型
 * 5. 源库多一个字段. oracle中多了一个alias_name字段
 * 6. 目标库多了一个字段. mysql中多了一个gmt_move字段，(简单的用迁移时的当前时间进行填充)
 *
 * 测试的表结构：
 * // oracle表
 * create table yugong_example_oracle
 * (
 *     id NUMBER(11)  ,
 *     name varchar2(32) ,
 *     alias_name  char(32) default ' ' not null,
 *     amount number(11,2),
 *     score  number(20),
 *     text_b blob,
 *     text_c clob,
 *     gmt_create date not null,
 *     gmt_modified date not null,
 *     CONSTRAINT yugong_example_oracle_pk_id  PRIMARY   KEY (id)
 * );
 *
 * // mysql表
 * create table test.yugong_example_mysql
 * (
 *     id bigint(20) unsigned auto_increment,
 *     display_name varchar(128) ,
 *     amount varchar(32),
 *     score bigint(20) unsigned ,
 *     text_b blob,
 *     text_c text,
 *     gmt_create timestamp not null,
 *     gmt_modified timestamp not null,
 *     gmt_move timestamp not null,
 *     CONSTRAINT yugong_example_mysql_pk_id  PRIMARY KEY (id)
 * );
 * </pre>
 *
 * @author agapple 2013-10-10 下午3:28:33
 */
public class BzRoomNewDataTranslator extends AbstractDataTranslator implements DataTranslator {

    public boolean translator(Record record) {
        record.setSchemaName("hddp-order");
        record.setTableName("bz_room_new");

        record.removeColumnByName("ORDER_CODE");
        record.removeColumnByName("BASIC_PRICE");
        record.removeColumnByName("SELL_PRICE");
        record.removeColumnByName("ROOM_STATUS_CODE");
        record.removeColumnByName("ROOM_PROPERTY_CODE");
        record.removeColumnByName("DEPTH");
        record.removeColumnByName("FACE_WIDTH");
        record.removeColumnByName("BUILD_AREA");
        record.removeColumnByName("CLEAR_HEIGHT");
        record.removeColumnByName("MEZZANINE");
        record.removeColumnByName("INTERIOR_OF_HOUSE_FLOOR");
        record.removeColumnByName("DRAIN");
        record.removeColumnByName("IS_SUBMIT");
        record.removeColumnByName("OWNER_SIGN_NUM");
        record.removeColumnByName("SOUND_INSULATION");
        record.removeColumnByName("REMARK");
        record.removeColumnByName("PARENT_ID");
        record.removeColumnByName("ROOM_FEATURE");
        record.removeColumnByName("AREA_FEATURE");
        record.removeColumnByName("WINDOWS");
        record.removeColumnByName("CURTAIN");
        record.removeColumnByName("EXHAUST_FAN");
        record.removeColumnByName("TERRACE");
        record.removeColumnByName("GARDEN_TYPE");
        record.removeColumnByName("NATURAL_CLAY");
        record.removeColumnByName("PARLOUR_COLOR");
        record.removeColumnByName("AREA_STUFF");
        record.removeColumnByName("WINDOW_FACE");
        record.removeColumnByName("COOKER_TYPE");
        record.removeColumnByName("COOKER_PUT_TYPE");
        record.removeColumnByName("FLASH");
        record.removeColumnByName("PHOTO_URL");
        record.removeColumnByName("SALES_PRICE");
        record.removeColumnByName("IS_CON");
        record.removeColumnByName("STYLE_RULE_ID");
        record.removeColumnByName("PHOTO_LAST_MODIFY_TIME");
        record.removeColumnByName("CONFIGURATIONSCHEME_ID");
        record.removeColumnByName("UPSELL_PRICE");
        record.removeColumnByName("UPSELL_DATE");
        record.removeColumnByName("ROOM_EVALUATION_TITLE");
        record.removeColumnByName("ROOM_EVALUATION_PRICE");
        record.removeColumnByName("ROOM_EVALUATION_CONFIG");
        record.removeColumnByName("ROOM_EVALUATION_HTYPE");
        record.removeColumnByName("ROOM_EVALUATION_NEIGHBOUR");
        record.removeColumnByName("ROOM_EVALUATION_TRUTH");
        record.removeColumnByName("TEST_COL");
        record.removeColumnByName("STATUS");
        record.removeColumnByName("RENEWAL_SALES_PRICE");
        record.removeColumnByName("EFFECT_DATE");
        record.removeColumnByName("LAST_MODIFY_TIME_SYNCHRONOUS");
        record.removeColumnByName("IS_AI_LOCK");
        record.removeColumnByName("FIRST_PHOTO_UUID");
        record.removeColumnByName("FIRST_PHOTO_PATH");
        record.removeColumnByName("SECOND_PHOTO_UUID");
        record.removeColumnByName("SECOND_PHOTO_PATH");
        record.removeColumnByName("CREATE_TIME");
        record.removeColumnByName("LAST_MODIFY_TIME_PRICE_STATUS");
        record.removeColumnByName("LAST_MODIFY_TIME_ORTHER");

        ColumnMeta newDataSyncDateMeta = new ColumnMeta("new_data_sync_date", Types.TIMESTAMP);
        ColumnValue newDataSyncDateColumn = new ColumnValue(newDataSyncDateMeta, null);
        newDataSyncDateColumn.setCheck(false);// 该字段不做对比
        record.addColumn(newDataSyncDateColumn);

        return super.translator(record);
    }
}
